<?php class News { 

    /***
     * DB Fields: id
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $id;

    /***
     * DB Fields: title
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $title;

    /***
     * DB Fields: message
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $message;

    /***
     * DB Fields: user
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $user;

    /***
     * DB Fields: date
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     **/
    var $date;

//--------------- GET METHODS ----------------------------- //
    /***
     * Get value for field: id
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result id
     **/
    function get_id( ) {
        // returns the value of id
        return $this->id;
    }


    /***
     * Get value for field: title
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result title
     **/
    function get_title( ) {
        // returns the value of title
        return $this->title;
    }


    /***
     * Get value for field: message
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result message
     **/
    function get_message( ) {
        // returns the value of message
        return $this->message;
    }


    /***
     * Get value for field: user
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result user
     **/
    function get_user( ) {
        // returns the value of user
        return $this->user;
    }


    /***
     * Get value for field: date
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @result date
     **/
    function get_date( ) {
        // returns the value of date
        return $this->date;
    }


//--------------- SET METHODS ----------------------------- //
    /***
     * Set value for field: id
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param id
     * @result void
     **/
    function set_id( $id ) {
        // sets the value of id
        $this->id = $id;
    }

    /***
     * Set value for field: title
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param title
     * @result void
     **/
    function set_title( $title ) {
        // sets the value of title
        $this->title = $title;
    }

    /***
     * Set value for field: message
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param message
     * @result void
     **/
    function set_message( $message ) {
        // sets the value of message
        $this->message = $message;
    }

    /***
     * Set value for field: user
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param user
     * @result void
     **/
    function set_user( $user ) {
        // sets the value of user
        $this->user = $user;
    }

    /***
     * Set value for field: date
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param date
     * @result void
     **/
    function set_date( $date ) {
        // sets the value of date
        $this->date = $date;
    }

//--------------- CRUD METHODS ----------------------------- //
    /***
     * Create a new Record: news
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param id
     * @param title
     * @param message
     * @param user
     * @param date
     * @result void
     **/
    function createnew_news( $id, $title, $message, $user, $date ) {

        // items to be inserted in the database 
        $_obj = array($id,
                      $title,
                      $message,
                      $user,
                      $date); 

        // database object connection
        $dbConn = $GLOBALS['dbConn'];

        // perform insert in the database
        $dbConn->insert("news", $_obj);
    }

    /***
     * Retrived an existing record: news
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param id
     * @result new News
     **/
    function get_news( $id ) {

        // retrive the data
        $dbConn = $GLOBALS['dbConn'];

        // retrieved value in the database
        $_resultSet = $dbConn->doQuery("SELECT * FROM news WHERE id = '$id'");

        $__newsObj = new news();
        // return the retrived from the database

        // create a new object
        $__obj = new News();
        $__obj->set_id($_resultSet[0]['id']);
        $__obj->set_title($_resultSet[0]['title']);
        $__obj->set_message($_resultSet[0]['message']);
        $__obj->set_user($_resultSet[0]['user']);
        $__obj->set_date($_resultSet[0]['date']);


        return $__obj;
    }

    /***
     * Update an existing record: news
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param id
     * @param itemsToBeUpdated = array()
     * @result void
     **/
    function update_news( $id, $itemsToBeUpdated = array() ) {

         // get database connection
         $dbConn = $GLOBALS['dbConn'];

         // performs update in the database
         foreach($itemsToBeUpdated as $_fName => $_fVal) { 
               $dbConn->addValuePair($_fName, $_fVal);
         }

         // perform update operation
         $dbConn->update("news", "id = '$id'");
    }

    /***
     * Delete an existing record: news
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param id
     * @result void
     **/
    function delete_news( $id ) {

         // get database connection
         $dbConn = $GLOBALS['dbConn'];

         // performs deletion of data
         $dbConn->delete("news", "id = '$id'");
    }

    /***
     * Retrived list of objects base on a given parameters: news
     *
     *
     * THIS IS a generated method using the DBClassGenerator 
     * created by John paul de Guzman <jpdguzman@gmail.com> 
     *
     * @param conditionalStatement = ''
     * @result collection of objects: News
     **/
    function list_news( $conditionalStatement = '' ) {

         $dbConn = $GLOBALS['dbConn'];
         // check if there is a given parameter list
         if(!empty($conditionalStatement)) { 
              $sqlStatement = "SELECT * FROM news WHERE $conditionalStatement"; 
         } else { 
              $sqlStatement = "SELECT * FROM news";
         }

         // retrieve the values base on the query result
         $__resObj = $dbConn->doQuery($sqlStatement);

         $__collectionOfObjects = array();
         foreach($__resObj as $__rs) { 
            $__newObj = new News();

            $__newObj->set_id($__rs['id']);
            $__newObj->set_title($__rs['title']);
            $__newObj->set_message($__rs['message']);
            $__newObj->set_user($__rs['user']);
            $__newObj->set_date($__rs['date']);

            // add object to collection 
            array_push($__collectionOfObjects, $__newObj);
         }

         // return collection of objects
         return $__collectionOfObjects;
    }

} ?>